# coding=utf-8
import maya.cmds as cmds
import os
import datetime
import getpass
import json
import CommonModule
#import core as timelimit
class HUD_min():

	def headsUpDisplaySet (self) :


		cmds.displayColor ('headsUpDisplayLabels' , 16 , dormant = True)
		cmds.displayColor ('headsUpDisplayValues' , 16 , dormant = True)
		cmds.headsUpDisplay ('HUDgongs' , s = 0 , b = 1 , ba = 'left' , c = self.hud_companyName , labelFontSize = 'large' , dfs = "large")
		cmds.headsUpDisplay ('HUDDate' , s = 0 , b = 2 , ba = 'left' , c = self.hud_sysDate , ev = 'timeChanged' , labelFontSize = 'large' , dfs = "large")



		cmds.headsUpDisplay ('HUD_resolution' , s = 2 , b = 1 , ba = 'left' , c = self.hud_resolution , ev = 'timeChanged' , labelFontSize = 'large' , dfs = "large")
		cmds.headsUpDisplay ('HUDTask' , s = 2 , b = 2 , ba = 'left' , label = 'Task:' , labelFontSize = 'large' , dfs = "large")

		cmds.headsUpDisplay ('HUDCam' , s = 4 , b = 1 , ba = 'left' , label = 'Cam:' , pre = 'cameraNames' , labelFontSize = 'large' , dfs = "large")
		cmds.headsUpDisplay ('HUDFocalLength' , s = 4 , b = 2 , ba = 'left' , dw = 100 , label = 'Focal Length:' , pre = 'focalLength' , labelFontSize = 'large' , dfs = "large")

		cmds.headsUpDisplay ('HUDUser' , s = 5 , b = 2 , ba = 'left' , label = 'User:' , c = self.HUD_User ,labelFontSize = 'large' , dfs = "large")
		#cmds.headsUpDisplay ('HUDPCName' , s = 5 , b = 1 , ba = 'left' , label = 'PCName:' , c = self.hud_ComputerName , labelFontSize = 'large' , dfs = "large")

		cmds.headsUpDisplay('HUDScence', s=7, b=1, ba='left', label='Scence:', c=self.hud_FileName, labelFontSize='large',dfs="large")
		cmds.headsUpDisplay('HUDSH', s=7, b=2, ba='left', label='SH:', c=self.hud_cam, labelFontSize='large', dfs="large")
		cmds.headsUpDisplay('HUDSQ', s=7, b=3, ba='left', label='SQ:', c=self.hud_sc, labelFontSize='large', dfs="large")
		cmds.headsUpDisplay('HUDEP', s=7, b=4, ba='left', label='EP:', c=self.hud_ep, labelFontSize='large', dfs="large")

		cmds.headsUpDisplay ('HUDFrame' , s = 9 , b = 2 , ba = 'left' , dw = 100 , label = 'Frame:\t\t\t' , pre = "currentFrame" , labelFontSize = 'large' , dfs = "large")

		cmds.headsUpDisplay ('HUDplaybackOptions' , s = 9 , b = 1 , ba = 'left' , dw = 100 , label = 'In / Out:\t' , c = self.hud_frameNo , ev = 'timeChanged' , labelFontSize = 'large' , dfs = "large")  #


	def star_headsUpDisplay (self) :
		#if timelimit.ProductActivation().Win() == 0:
		#	return

		list_headsUpDisplay = cmds.headsUpDisplay (listHeadsUpDisplays = 1)
		if not list_headsUpDisplay:
			self.headsUpDisplaySet()
		elif not cmds.headsUpDisplay ('HUDDate', ex=1):
			for i in list_headsUpDisplay:
				cmds.headsUpDisplay(i, remove=True)
			self.headsUpDisplaySet()
		elif cmds.headsUpDisplay ('HUDDate', ex=1):
			for i in list_headsUpDisplay:
				cmds.headsUpDisplay(i, remove=True)

	def expressionRemover (self) :
		if not cmds.headsUpDisplay ('HUDDate', ex=1):
			for i in cmds.headsUpDisplay (listHeadsUpDisplays = 1):
				print i
				cmds.headsUpDisplay(i, remove=True)
		print '99999999999999'

	def hud_UserName(self):
		result = cmds.promptDialog(
			title='Rename Object',
			message=u'制作人姓名:',
			button=['OK', 'Cancel'],
			defaultButton='OK',
			cancelButton='Cancel',
			dismissString='Cancel')

		if result == 'OK':
			UserName = {}
			user = getpass.getuser()

			text = cmds.promptDialog(query=True, text=True)
			UserName['UserName'] = text.encode('utf-8')
			storageProjectSettings = 'C:/Users/' + user + '/Documents/RareWolf/'
			json_Path = storageProjectSettings + 'UserName.json'
	
			
			with open(json_Path, 'w') as f:
				json.dump(UserName, f, ensure_ascii=False)
			'''
			out_file = open(json_Path, 'w',encoding='utf-8')
			json.dump(UserName, out_file, indent=4)
			out_file.close()
			'''

	def HUD_User(self):
		user = getpass.getuser()
		ProjectSettings_LocalPath = 'C:/Users/' + user + '/Documents/RareWolf/'
		ProjectSettings_LocalFile = os.listdir(ProjectSettings_LocalPath)

		for tmp in ProjectSettings_LocalFile:
			if 'UserName' in tmp:
				with open(ProjectSettings_LocalPath + tmp, 'r') as f:
					json_data = json.load(f)
					UserName = json_data['UserName']
				HUD_User = UserName
				return HUD_User
			#else:
			#	self.hud_UserName()



	def hud_companyName (self) :
		user = getpass.getuser()
		ProjectSettings_LocalPath = 'C:/Users/' + user + '/Documents/RareWolf/'
		ProjectSettings_LocalFile = os.listdir(ProjectSettings_LocalPath)
		for tmp in ProjectSettings_LocalFile:
			if 'ProjectSettings' in tmp:
				with open(ProjectSettings_LocalPath + tmp, 'r') as f:
					json_data = json.load(f)
					self.Project_Name = json_data['Project_Name']
					#self.XlsxProject_Path = json_data['Project_XLSX']
					## 本地路径
					#self.local_Path = json_data['Project_local_Path']
					## 网盘路径
					#self.ServerX_Project = json_data['Project_ServerX_Path']
					#print self.ServerX_Project
		hud_companyName = self.Project_Name
		return hud_companyName
	def hud_FileName (self) :
		File_sceneName = cmds.file (q = 1 , sceneName = 1,shortName = 1)

		return File_sceneName.split('-')[0]+'.mb'
	def hud_ep (self) :
		File_sceneName = cmds.file(q=1, sceneName=1, shortName=1)
		if not File_sceneName:
			pass
		else:
			ep = File_sceneName.split('_')[0]
			return ep
	def hud_sc (self) :
		File_sceneName = cmds.file(q=1, sceneName=1, shortName=1)
		if not File_sceneName:
			pass
		else:
			sc = File_sceneName.split('_')[1]
			return sc
	def hud_cam (self) :
		File_sceneName = cmds.file(q=1, sceneName=1, shortName=1)
		if not File_sceneName:
			pass
		else:
			cam = File_sceneName.split('_')[2]
			return cam
	def hud_sysDate (self) :
		time = datetime.datetime.now ().strftime ('%Y-%m-%d %H:%M:%S')
		return time


	def hud_frameNo (self) :
		#CommonModule.MinTimes()
		#
		#curTime = cmds.currentTime (q = 1)
		#framemin = int( cmds.playbackOptions (q = 1 , min = 1) )
		#framemax = int(cmds.playbackOptions (q = 1 , max = 1))
		return str (CommonModule.MinTimes()) + "/" + str (CommonModule.MaxTimes())


	def hud_ComputerName (self) :
		name = os.environ.get ("COMPUTERNAME")
		return name


	def hud_resolution (self) :
		hud_resolution = str (cmds.getAttr ("defaultResolution.width")) + " x " + str (cmds.getAttr ("defaultResolution.height"))
		return hud_resolution


#HUD_min().star_headsUpDisplay ()

